package ex_from_web;

/**
 * Java Interface inheritance example
 * Interface extends another interface
 */
    interface Device {
        void switchOn();
    }
    
    //Heating device is Device (can be switched ON), 
    //but also has more specific attribute - maxTemperature
    interface HeatingDevice extends Device {
        void showMaxTemperature();
    }
    
    class TV implements Device {
        String model;
        
        public TV(String model) {
            this.model = model;
        }
        
        public void switchOn() {
            System.out.println("TV " + model + " switched ON!");
        }
    }
    
    class Computer implements Device {
        String model;
        
        public Computer(String model) {
            this.model = model;
        }
        
        public void switchOn() {
            System.out.println("Computer " + model + " switched ON!");
        }
    }
    class Radio implements Device {
        String model;
        
        public Radio(String model) {
            this.model = model;
        }
        
        public void switchOn() {
            System.out.println("Radio " + model + " switched ON!");
        }
        
    }
    
    class Heater implements HeatingDevice {
        String model;
        int maxTemperature;
        
        public Heater(String model, int maxTemperature) {
            this.model = model;
            this.maxTemperature = maxTemperature;
        }
        
        public void showMaxTemperature() {
            System.out.println("Max temperature for heater " + model + " is " + maxTemperature + "C");
        }

        public void switchOn() {
            System.out.println("Heater " + model + " switched ON!");
        }
        
    }
    
    class Microwave implements HeatingDevice {
        String model;
        int maxTemperature;
        
        public Microwave(String model, int maxTemperature) {
            this.model = model;
            this.maxTemperature = maxTemperature;
        }
        
        public void showMaxTemperature() {
            System.out.println("Max temperature for microwave " + model + " is " + maxTemperature + "C");
        }

        public void switchOn() {
            System.out.println("Microwave "  + model + " switched ON!");
        }        
    }
    
    public class inheritance_example {
        
    public static void main(String[] args) {
        Device tv1 = new TV("T-1");
        Device radio1 = new Radio("R-1");
        Device computer1 = new Computer("C-1");
        HeatingDevice heater1 = new Heater("H-1", 38);
        HeatingDevice microwave1 = new Microwave("M-1", 80);
        tv1.switchOn();
        radio1.switchOn();
        computer1.switchOn();
        heater1.switchOn();
        heater1.showMaxTemperature();
        microwave1.switchOn();
        microwave1.showMaxTemperature();
    }
}